package com.baizhi.rjb.Controller;

import com.baizhi.rjb.dto.*;
import com.baizhi.rjb.entity.Category;
import com.baizhi.rjb.service.CategoryService;
import com.baizhi.rjb.vo.CategoryGoryVo;
import com.baizhi.rjb.vo.CategoryStaVo;
import com.baizhi.rjb.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @ResponseBody
    @RequestMapping(value = "queryOnePage",method = RequestMethod.POST)
    public CategoryVo queryOnePage(@RequestBody CategoryDto categoryDto){
        return categoryService.page(categoryDto.getPage(), categoryDto.getPageSize());
    }
    @ResponseBody
    @RequestMapping(value = "add",method = RequestMethod.POST)
    public CategoryStaVo add(@RequestBody CategoryAddDto categoryAddDto){
        return categoryService.add(categoryAddDto);
    }

    @ResponseBody
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public CategoryStaVo delete(@RequestBody CategoryDelDto categoryDelDto){
        return categoryService.delete(categoryDelDto);
    }
    @ResponseBody
    @RequestMapping(value = "queryById",method = RequestMethod.GET)
    public Category queryById(int id){
        return categoryService.queryOne(id);
    }
    @ResponseBody
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public CategoryStaVo update(@RequestBody CategoryUpdDto categoryUpdDto){
        System.out.println(categoryUpdDto);
        return categoryService.update(categoryUpdDto);
    }
    @ResponseBody
    @RequestMapping(value = "queryTwoPage",method = RequestMethod.POST)
    public CategoryVo queryTwoPage(@RequestBody CategoryTwoDto categoryDto){
        return categoryService.page(categoryDto.getPage(),categoryDto.getPageSize(),categoryDto.getCategoryId());
    }
    @ResponseBody
    @RequestMapping(value = "queryByLevelsCategory",method = RequestMethod.POST)
    public List<CategoryGoryVo> queryByLevelsCategory(int levels){
        return categoryService.cate(levels);
    }
}
